#include<bits/stdc++.h>
#define F(i,x,y) for (int i=(x);i<=(y);i++)
#define R(i,x,y) for (int i=(x);i>=(y);i--)
#define p2i pair<int,int>
#define ll long long
#define fi first
#define se second
#define pub push_back
#define ins insert
#define puf push_front
#define vec vector
#define umap unordered_map
#define uset unordered_set
#define popf pop_front
#define popb pop_back
#define nb(x) (1<<((x)-1))
#define x1 __melody1
#define x2 __melody2
#define y1 __melody3
#define y2 __melody4
#define iosoptim ios::sync_with_stdio(0);cin.tie(0);
using namespace std;

const bool MT = 0;
int n,m;
char tpy_plays_lavaloons[2000005],stupid_indian_cheaters[2000005];
char &a(int i,int j) {
    return tpy_plays_lavaloons[(i-1)*m+j];
}
char &b(int i,int j) {
    return stupid_indian_cheaters[(i-1)*m+j];
}
const int dx[]={0,1,0,-1,0},dy[]={-1,0,1,0,0};
int test (int r) {
    F(i,1,n) {
        F(j,1,m) {
            if (a(i,j)=='.') b(i,j)='.';
            else b(i,j)='0';
        }
    }
    int res=0;
    F(i,1,n) {
        F(j,1,m) {
            if (a(i,j)=='.') continue;
            if ((i+2*j)%5==r) {
                res++;
                b(i,j)='1';
            }
        }
    }
    F(i,1,n) {
        F(j,1,m) {
            if (a(i,j)=='.') continue;
            bool flag=0;
            F(d,0,4) {
                int nx=i+dx[d],ny=j+dy[d];
                if (1<=nx&&nx<=n&&1<=ny&&ny<=m&&b(nx,ny)=='1') {
                    flag=1;
                }
            }
            if (!flag) {
                res++;
                b(i,j)='1';
            }
        }
    }
    return res;
}
void solve(){
	// Insert your code here
    cin>>n>>m;
    F(i,1,n) {
        F(j,1,m) {
            cin>>a(i,j);
        }
    }
    int sum=0;
    F(i,1,n) {
        F(j,1,m) {
            if (a(i,j)=='#') {
                sum+=5;
                F(d,0,3) {
                    int nx=i+dx[d],ny=j+dy[d];
                    if (1<=nx&&nx<=n&&1<=ny&&ny<=m&&a(nx,ny)=='#') sum--;
                }
            }
        }
    }
    F(i,0,4) {
        if (test (i)<=sum/5) {
            F(x,1,n) {
                F(y,1,m) {
                    cout<<b(x,y);
                }
                cout<<"\n";
            }
            return;
        }
    }
}
void cleanup() {

}
int main (){
    freopen ("indian.in","r",stdin);
    freopen ("indian.out","w",stdout);
    iosoptim
	int testcases=1;
	if(MT) cin>>testcases;
	while(testcases--){
		solve();
		cleanup();
	}
	return 0;
}